package leetcode;

import java.util.Arrays;

public class Lc34 {

    int left, right;

    public int[] searchRange(int[] nums, int target) {
        left = right = -1;
        binarySearch(nums, target, 0, nums.length - 1);

        return new int[]{left, right};
    }

    public void binarySearch(int[] nums, int target, int l, int r) {
        if (l > r)
            return;
        int mid = (l + r) / 2;
        if (nums[mid] > target)
            binarySearch(nums, target, l, mid - 1);
        else if (nums[mid] < target)
            binarySearch(nums, target,mid + 1, r);
        else {
            if (left == -1) {
                left = right = mid;
            } else {
                left = Math.min(left, mid);
                right = Math.max(mid, right);
            }
            binarySearch(nums, target, l, mid - 1);
            binarySearch(nums, target, mid + 1, r);
        }


    }









    public static void main(String[] args) {
        Lc34 lc34 = new Lc34();
        int[] arr = {5,7,7,8,8,10};
        int target = 6;
        Arrays.stream(lc34.searchRange(arr, target)).forEach(System.out::println);
    }




}
